using System;
using System.Collections;

namespace GeoFramework.Gps
{
	/// <summary>
	/// Facilitates comparisons and sorting of satellites based on their pseudo-random
	/// number.
	/// </summary>
	public sealed class SatellitePseudorandomNumberComparer : IComparer
	{
		public SatellitePseudorandomNumberComparer()
		{
		}

		public static readonly SatellitePseudorandomNumberComparer Default = new SatellitePseudorandomNumberComparer();

		public int Compare(Satellite x, Satellite y)
		{
			return x.PseudorandomNumber.CompareTo(y.PseudorandomNumber);
		}

		#region IComparer Members

		int IComparer.Compare(object x, object y)
		{
			return this.Compare((Satellite)x, (Satellite)y);
		}

		#endregion
	}

	/// <summary>
	/// Facilitates comparisons and sorting of satellites based on their radio signal
	/// strength.
	/// </summary>
	public sealed class SatelliteSignalToNoiseRatioComparer : IComparer
	{
		public SatelliteSignalToNoiseRatioComparer()
		{
		}

		public static readonly SatelliteSignalToNoiseRatioComparer Default = new SatelliteSignalToNoiseRatioComparer();

		public int Compare(Satellite x, Satellite y)
		{
			int Result = x.SignalToNoiseRatio.Value.CompareTo(y.SignalToNoiseRatio.Value);
			if(Result == 0)
				return x.PseudorandomNumber.CompareTo(y.PseudorandomNumber);
			else
				return -Result;
		}

		#region IComparer Members

		int IComparer.Compare(object x, object y)
		{
			return this.Compare((Satellite)x, (Satellite)y);
		}

		#endregion
	}
}
